
function DropMenu(id,name,icon,disabled,clickMethod){
	this.id = id ;
	this.name = name ;
	this.icon = icon ;
	this.disabled = disabled ;
	this.clickMethod = clickMethod ;
	return this ;
}

DropMenu.prototype.getHtmlTag = function(){
	var row = new HtmlTag("tr");
	var tag = new HtmlTag("td");
	if(this.disabled){
		tag.setAttribute("class","dropmenu dp-disabled");
	}else{
		tag.setAttribute("class","dropmenu dp-blur");
		tag.setAttribute("onmouseover","this.className='dropmenu dp-focus'");
		tag.setAttribute("onmouseout","this.className='dropmenu dp-blur'");
		tag.setAttribute("onclick","hideDropMenuForcely();"+this.clickMethod);
	}
	if(this.icon != null && this.icon != ""){
		tag.setAttribute("style","background-image:url('"+this.icon+"');");
	}
	tag.addChild(this.name);
	row.addChild(tag);
	return row;
}

function SeperateLine(){
	this.id = "";
	return this ;
}

SeperateLine.prototype.getHtmlTag = function(){
	var row = new HtmlTag("tr");
	var tag = new HtmlTag("td");
	tag.setAttribute("class","dropmenu-seperator");
	return tag;
}

function showDropMenus(matrix,e){
	var div = document.createElement("div");
	div.className = "dropmenu_container";
	div.setAttribute("id","dropmenu_00");
	
	if(isMSIE){
		div.attachEvent("onmouseover",function(){lockDropMenu(div);});
		div.attachEvent("onmouseout",function(){hideDropMenu(div);});
	}else{
		div.setAttribute("onmouseover","lockDropMenu(this)");
		div.setAttribute("onmouseout","hideDropMenu(this)");
	}

	var table = document.createElement("table");
	table.className = "dropmenu_table";
	table.setAttribute("cellpadding",'0');
	table.setAttribute("cellspacing",'0');


	for(var i=0;i<matrix.length;i++){
		var menu = matrix[i] ;
		
		var row = document.createElement("tr");
		var col = document.createElement("td");

		if(menu.id == ""){ // seperator
			col.className = "dropmenu-seperator";
		}else if(menu.disabled){
			col.className = "dropmenu dp-disabled";
		}else{
			col.className = "dropmenu dp-blur";
			col.setAttribute("onmouseover","this.className='dropmenu dp-focus'");
			col.setAttribute("onmouseout","this.className='dropmenu dp-blur'");
			col.setAttribute("onclick","hideDropMenuForcely();"+menu.clickMethod);
		}
		if(menu.icon != null && menu.icon != ""){
			if(isMSIE){
				col.style.backgroundImage = "url('" + menu.icon + "')" ;
			}else{
				col.setAttribute("style","background-image:url('" + menu.icon + "');");
			}
		}
		if(menu.id != ""){ // seperator
			var textNode = document.createTextNode(menu.name);
			col.appendChild(textNode);
		}
		row.appendChild(col);
		table.appendChild(row);
	}

	document.body.appendChild(div);
	div.style.left = getPositionX(e) ;
	div.style.top = getPositionY(e) ;

	if(isMSIE){
		div.innerHTML = table.outerHTML ;
	}else{
		div.appendChild(table);
	}

	div.style.display = "block" ;

}


function getPositionX(event){
	var x = event.clientX - 120 ;
	return x ;
}
function getPositionY(event){
	var y = event.clientY - 5 ;
	return y ;
}

var dropMenuLock ;
var dropMenuBar ;
var dropMenuBox ;
function lockDropMenu(me){
	dropMenuLock = true ;
	return ;
}
function hideDropMenu(me){
	dropMenuLock = false ;
	dropMenuBox = me ;
	dropMenuBar = setTimeout("hideDropMenuNow()",500);
}

function hideDropMenuNow(){
	if(dropMenuLock){
		return ;
	}
	dropMenuBox.style.display = "none";
}
function hideDropMenuNow(){
	if(dropMenuLock){
		return ;
	}
	dropMenuBox.style.display = "none";
}

function hideDropMenuForcely(){
	var div = document.getElementById("dropmenu_00");
	div.style.display = "none";
}

function clearDropMenus(){
	var node = document.getElementById("dropmenu_00");
	if(node != null){
		var p = node.parentNode ;
		p.removeChild(p.lastChild) ;
	}
}